<!-- additional stylesheet hear -->
<link rel="stylesheet" type="text/css" href="<?=base_url();?>application/css/thickbox.css" media="screen" />
<link rel="stylesheet" type="text/css" href="<?=base_url();?>application/css/style.css"/>
<!-- additional javascript hear -->
<script src="http://maps.google.com/maps?file=api&amp;v=3&amp;sensor=false&amp;key=ABQIAAAA1QnAxBtPWpvkkIJ1M7uNRhSaZr1EoDksNVh5CWAzOfD4zrQihBTtbZTHEHq4q97m9-r8YVi8kTiliA" type="text/javascript"></script>
<script type="text/javascript" src="<?=base_url();?>application/scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<?=base_url();?>application/scripts/thickbox.js"></script>
<script type="text/javascript"> 
    //<![CDATA[
    
    if (GBrowserIsCompatible()) { 
 
    var map;
    var geo;
    var reasons=[];
 
 
    function initialize() {
      map = new GMap(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(13.806, 100.728),9);
      
      // ====== Create a Client Geocoder ======
      geo = new GClientGeocoder(); 
 
      // ====== Array for decoding the failure codes ======
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
    }
 
      // ====== Plot a marker after positive reponse to "did you mean" ======
      function place(lat,lng) {
        var point = new GLatLng(lat,lng);
        map.setCenter(point,14); 
        map.addOverlay(new GMarker(point));

		document.getElementById("lat").value = lat;
		document.getElementById("lng").value = lng;
        document.getElementById("message").innerHTML = "";
      }
 
      // ====== Geocoding ======
      function showAddress() {
        var search = document.getElementById("search").value;
        // ====== Perform the Geocoding ======        
        geo.getLocations(search, function (result)
          {
            map.clearOverlays(); 
            if (result.Status.code == G_GEO_SUCCESS) {
              // ===== If there was more than one result, "ask did you mean" on them all =====
              if (result.Placemark.length > 1) { 
                document.getElementById("message").innerHTML = "หรือคุณอาจหมายถึง:";
                // Loop through the results
                for (var i=0; i<result.Placemark.length; i++) {
                  var p = result.Placemark[i].Point.coordinates;
                  document.getElementById("message").innerHTML += "<br>"+(i+1)+": <a href='javascript:place(" +p[1]+","+p[0]+")'>"+ result.Placemark[i].address+"<\/a>";
                }
              }
              // ===== If there was a single marker =====
              else {
                document.getElementById("message").innerHTML = "";
                var p = result.Placemark[0].Point.coordinates;
                place(p[1],p[0]);
              }
            }
            // ====== Decode the error status ======
            else {
              var reason="Code "+result.Status.code;
              if (reasons[result.Status.code]) {
                reason = reasons[result.Status.code]
              } 
              alert('Could not find "'+search+ '" ' + reason);
            }
          }
        );
      }
    }
    
    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
 
    // This Javascript is based on code provided by the
    // Community Church Javascript Team
    // http://www.bisphamchurch.org.uk/   
    // http://econym.org.uk/gmap/
 
    //]]>
    </script> 
</head>
<body onLoad="initialize();" onUnload="GUnload();">
	<?php
	if($this->session->flashdata('success'))
	{ 
	echo '<div class="success">' . $this->session->flashdata('success') . '</div>';
	}
?>
<div align="center">
<?php echo form_open('profile/addPoint');?>
  <input id="search" size="40" type="text"  /> 
  <input class="button" type="button" onclick="showAddress(); return false" value="Find!" /> 
  <input size="20" type="hidden" name="latitude" id="lat"  value=""  />
	<input size="20" type="hidden" name="longitude" id="lng"  value="" />
	<input size="20" type="hidden" name="photoId" value="<?echo $this->uri->segment(3);?>" />
	<input class="button" type="submit" value="Save Point">
</form>

    <div id="message"></div> 
	<div id="map" style="border:1px solid #fff; width: 560px; height: 400px"></div>
	<p>© 2010 Panoramap Development.</p>
</div>
</body>
</html>